HomePrize.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. "use client";
  2. import { gamesNoticeWinApi, GameListRep } from "@/api/home";
  3. import Box from "@/components/Box";
  4. import { Button, Popup } from "antd-mobile";
  5. import { useTranslations } from "next-intl";
  6. import { FC, useEffect, useState } from "react";
  7. import { Autoplay } from "swiper/modules";
  8. import { Swiper, SwiperSlide } from "swiper/react";
  9. import { useRouter } from "@/i18n/routing";
  10. import { getToken } from "@/utils/Cookies";
  11. import { useWalletStore } from "@/stores/useWalletStore";
  12. import useGame from "@/hooks/useGame";
  13. import styles from "@/components/Card/style.module.scss";
  14. interface Props {}
  15. const HomePrize: FC<Props> = () => {
  16. const t = useTranslations("HomePage");
  17. const tt = useTranslations("Game");
  18. const [winImg, setWinImg] = useState<any>([]);
  19. const gamesNoticeWinRequest = async () => {
  20. gamesNoticeWinApi()
  21. .then((res: any) => {
  22. if (res.code === 200) setWinImg(res.data || []);
  23. })
  24. };
  25. useEffect(() => {
  26. gamesNoticeWinRequest()
  27. }, [])
  28. const [visible, setVisible] = useState(false);
  29. const [gameInfo, setGameInfo] = useState({});
  30. const handler = (game: GameListRep) => {
  31. setVisible(true);
  32. setGameInfo(game)
  33. console.log(game)
  34. };
  35. const router = useRouter();
  36. const token = getToken();
  37. const wallet = useWalletStore((state) => state.wallet);
  38. const { getGameUrl } = useGame();
  39. const playGameHandler = () => {
  40. setVisible(true);
  41. if (!token) {
  42. router.push("/login?redirect=/");
  43. return;
  44. }
  45. let groupType = 1;
  46. if (groupType === 1 && Number(wallet.score) + wallet.point <= 0) {
  47. router.push("/deposit");
  48. return;
  49. }
  50. const params = {
  51. id: gameInfo.id + "",
  52. mode: groupType!,
  53. };
  54. getGameUrl(gameInfo, params);
  55. };
  56. return (
  57. <div className={"my-[0.0694rem]"}>
  58. <div className={"mb-[0.0347rem]"}>{t("prize")}</div>
  59. <Swiper
  60. slidesPerView={3.2}
  61. spaceBetween={30}
  62. pagination={{
  63. clickable: true,
  64. }}
  65. loop
  66. autoplay={{
  67. delay: 3000,
  68. }}
  69. modules={[Autoplay]}
  70. className="mySwiper"
  71. >
  72. {winImg.map((prize: any, index: number) => (
  73. <SwiperSlide key={index}>
  74. <div className={"w-[1.1rem] bg-[#1c1e22]"} onClick={() => handler(prize)}>
  75. <img className={"h-[1.54rem]"} src={prize.game_icon} alt="" />
  76. <div className={"px-[0.13rem] pb-[0.0347rem] text-[0.13rem]"}>
  77. <p className={"text-[#98a7b5]"}>{prize.phone ? prize.phone.slice(0,3) + '*****' + prize.phone.slice(-3): ''}</p>
  78. <p className={"text-[#43c937]"}>R${prize.amount}</p>
  79. </div>
  80. </div>
  81. </SwiperSlide>
  82. ))}
  83. </Swiper>
  84. <Popup
  85. visible={visible}
  86. onMaskClick={() => {
  87. setVisible(false);
  88. }}
  89. onClose={() => {
  90. setVisible(false);
  91. }}
  92. showCloseButton={true}
  93. getContainer={() => document.querySelector("#app")!}
  94. bodyStyle={{ background: "#1c1c1c" }}
  95. >
  96. <Box className={"w-1/1 flex w-[4.02rem] flex-1"}>
  97. <div className={styles.cardWrap} style={{ width: "1.1rem" }}>
  98. <img
  99. src={gameInfo?.game_icon}
  100. alt={gameInfo?.game_name_cn}
  101. className={"h-[100%] w-[100%]"}
  102. />
  103. </div>
  104. <div className={styles.cardWrapGmeInfo}>
  105. <p className={"h-[0.6rem]"}>{gameInfo?.game_name_cn}</p>
  106. <div className={"flex w-[2.2rem] justify-around"}>
  107. {/*<Button*/}
  108. {/* onClick={playGameHandler}*/}
  109. {/* className={*/}
  110. {/* "h-[0.39rem] w-[0.89rem] rounded-[0.05rem] text-[0.15rem]" +*/}
  111. {/* " bg-[#3a3a3a]" +*/}
  112. {/* " font-bold"*/}
  113. {/* }*/}
  114. {/*>*/}
  115. {/* {t("demo")}*/}
  116. {/*</Button>*/}
  117. <Button
  118. onClick={playGameHandler}
  119. style={{
  120. "--background-color": "#009d80",
  121. "--border-color": "#009d80",
  122. }}
  123. className={`h-[0.39rem] w-[0.89rem] rounded-[0.05rem] bg-[#] text-[0.15rem] font-bold`}
  124. >
  125. {tt("join")}
  126. </Button>
  127. </div>
  128. </div>
  129. </Box>
  130. </Popup>
  131. </div>
  132. );
  133. };
  134. export default HomePrize;